<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/5/25
 * Time: 16:34
 */
namespace app\common\validate;
use think\Validate;
class Driver extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'name' => 'require',
        'sex' => 'require|in:1,2',
        'mobile' => 'require|checkMobile',

    ];
    protected function checkMobile($value,$rule,$data)
    {
        $rule = '/^0?(13|14|15|17|18)[0-9]{9}$/';
        $result = preg_match($rule, $value);
        if (!$result) {
           return false;
        }
        return true;
    }
    /**
     * 提示消息
     */
    protected $message = [
        'name.require' => '姓名不能为空',
        'sex.require' => '性别不能为空',
        'sex.in' => '性别数值错误',
        'mobile.require' => '手机号不能为空',
        'mobile.checkMobile' => '手机号格式不正确',
    ];

    /**
     * 字段描述
     */
    protected $field = [
    ];

    /**
     * 验证场景
     */
    protected $scene = [
        /*'add'  => ['username',  'nickname', 'password'],
        'edit' => ['username', 'nickname', 'password'],*/
    ];
}